home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 376-400 / disk_386 / xlispstat / src2.lzh / XLisp-Stat / xsiview.c < prev    next >
C/C++ Source or Header  |  1990-10-02  |  11KB  |  429 lines

  1. /* xsiview - XLISP interface to IVIEW dynamic graphics package.        */
  2. /* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney                  */
  3. /* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
  4. /* You may give out copies of this software; for conditions see the    */
  5. /* file COPYING included with this distribution.                       */
  6.  
  7. #include <string.h>
  8. #include "xlisp.h"
  9. #include "osdef.h"
  10. #ifdef ANSI
  11. #include "xlproto.h"
  12. #include "xlsproto.h"
  13. #include "iviewproto.h"
  14. #include "Stproto.h"
  15. #else
  16. #include "xlfun.h"
  17. #include "xlsfun.h"
  18. #include "iviewfun.h"
  19. #include "Stfun.h"
  20. #endif ANSI
  21. #include "xlsvar.h"
  22.  
  23. /* forward declarations */
  24. #ifdef ANSI
  25. LVAL clear_data(int);
  26. int check_locations(LVAL,int);
  27. void set_locations(IVIEW_WINDOW,LVAL,int,LVAL,int,int,int),
  28.      check_strings(int,LVAL);
  29. #else
  30. LVAL clear_data();
  31. int check_locations();
  32. void set_locations(),
  33.      check_strings();
  34. #endif ANSI
  35.  
  36. /**************************************************************************/
  37. /**                                                                      **/
  38. /**                    General IView Data Functions                      **/
  39. /**                                                                      **/
  40. /**************************************************************************/
  41.  
  42. static int check_locations(data, vars)
  43.     LVAL data;
  44.     int vars;
  45. {
  46.   LVAL seq, x;
  47.   int i, j, n;
  48.   
  49.   if (fixp(data)) {
  50.     if (getfixnum(data) <= 0) xlerror("too few points", data);
  51.     else return(getfixnum(data));
  52.   }
  53.   
  54.   if (! consp(data)/* || llength(data) != vars */)
  55.     xlerror("bad variable list", data);
  56.   
  57.   if (! sequencep(car(data))) xlerror("not a sequence", car(data));
  58.   n = seqlen(car(data));
  59.   
  60.   for (i = 0; i < vars && consp(data); i++, data = cdr(data)) {
  61.     if (! sequencep(car(data))) xlerror("not a sequence", car(data));
  62.     if (seqlen(car(data)) != n) xlfail("sequences of different lengths");
  63.     for (j = 0, seq = car(data); j < n; j++) {
  64.       x = getnextelement(&seq, j);
  65.       if (! numberp(x)) xlerror("not a number", x);
  66.     }
  67.   }
  68.   return(n);
  69. }
  70.  
  71. static void set_locations(w, object, type, data, vars, oldn, n)
  72.     IVIEW_WINDOW w;
  73.     LVAL object, data;
  74.     int type;
  75.     int  vars, oldn, n;
  76. {
  77.   LVAL seq, arg;
  78.   int i, j;
  79.   double x;
  80.  
  81.   if (fixp(data)) return;
  82.   if (! xlgetkeyarg(sk_scale, &arg)) arg = s_true;
  83.   
  84.   for (i = 0; i < vars && consp(data); i++, data = cdr(data)) {
  85.     for (j = oldn, seq = car(data); j < n; j++) {
  86.       x = makedouble(getnextelement(&seq, j - oldn));
  87.       switch (type) {
  88.       case 'P': IViewSetPointValue(w, i, j, x); break;
  89.       case 'L': IViewSetLineValue(w, i, j, x); break;
  90. #ifdef USESTRINGS
  91.       case 'S': IViewSetStringValue(w, i, j, x); break;
  92. #endif /* USESTRINGS */
  93.       }
  94.     }
  95.   }
  96. }
  97.  
  98. static void check_strings(n, strings)
  99.     int n;
  100.     LVAL strings;
  101. {
  102.   int i;
  103.   LVAL element;
  104.   
  105.   if (! sequencep(strings)) xlerror("not a sequence", strings);
  106.   if (n != seqlen(strings)) xlerror("wrong sequence length", strings);
  107.   for (i = 0; i < n; i++) {
  108.     element = getnextelement(&strings, i);
  109.     if (! stringp(element)) xlerror("not a string", element);
  110.   }
  111. }
  112.  
  113. static LVAL clear_data(which)
  114.     int which;
  115. {
  116.   IVIEW_WINDOW w;
  117.   LVAL object;
  118.   
  119.   object = xlgaobject();
  120.   w = get_iview_address(object);
  121.   
  122.   switch(which) {
  123.   case 'P': IViewClearPoints(w);  break;
  124.   case 'L': IViewClearLines(w);   break;
  125. #ifdef USESTRINGS
  126.   case 'S': IViewClearStrings(w); break;
  127. #endif /* USESTRINGS */
  128.   }
  129.   check_redraw(object, TRUE, TRUE);
  130.   return(NIL);
  131. }
  132.  
  133. /**************************************************************************/
  134. /**                                                                      **/
  135. /**                      IView Point Data Functions                      **/
  136. /**                                                                      **/
  137. /**************************************************************************/
  138.  
  139. void internal_iview_add_points(w, object, data)
  140.     IVIEW_WINDOW w;
  141.     LVAL object, data; 
  142. {
  143.   LVAL labels, arg;
  144.   int i, n, oldn, vars, sym, hsym;
  145.   char *str;
  146.   StGWWinInfo /* char */ *gwinfo = IViewWindowWinInfo(w); /* changed JKL */
  147.  
  148.   if (! xlgetkeyarg(sk_point_labels, &labels)) labels = NIL;
  149.   
  150.   vars = IViewNumVariables(w);
  151.   oldn = IViewNumPoints(w);
  152.   n = check_locations(data, vars);
  153.   
  154.   IViewAddPoints(w, n);
  155.   n = IViewNumPoints(w);
  156.   set_locations(w, object, 'P', data, vars, oldn, n);
  157.   
  158.   if (labels != NIL) {
  159.     check_strings(n - oldn, labels);
  160.     for (i = oldn; i < n; i++) {
  161.       str = (char *) getstring(getnextelement(&labels, i - oldn));
  162.       IViewSetPointLabel(w, i, str);
  163.     }
  164.   }
  165.   if (xlgetkeyarg(sk_color, &arg)) {
  166.     StGWSetUseColor(gwinfo, TRUE);
  167.     for (i = oldn; i < n; i++)
  168.       IViewSetPointColor(w, i, decode_lisp_color(arg));
  169.   }
  170.   if (xlgetkeyarg(sk_symbol, &arg)) {
  171.     decode_point_symbol(arg, &sym, &hsym);
  172.     for (i = oldn; i < n; i++)
  173.       IViewSetPointSymbol(w, i, sym, hsym);
  174.   }
  175. }
  176.  
  177. LVAL iview_add_points()
  178. {
  179.   IVIEW_WINDOW w;
  180.   LVAL object, data;
  181.   int old_n, n;
  182.   
  183.   object = xlgaobject();
  184.   w = get_iview_address(object);
  185.   data = xlgetarg();
  186.   
  187.   old_n = IViewNumPoints(w);
  188.   internal_iview_add_points(w, object, data);
  189.   n = IViewNumPoints(w);
  190.   check_add_to_screen(object, 'P', old_n, n, FALSE);
  191.   return(NIL);
  192. }
  193.  
  194. LVAL iview_clear_points() { return(clear_data('P')); }
  195.  
  196. /**************************************************************************/
  197. /**                                                                      **/
  198. /**                      IView Line Data Functions                       **/
  199. /**                                                                      **/
  200. /**************************************************************************/
  201.  
  202. void internal_iview_add_lines(w, object, data)
  203.     IVIEW_WINDOW w;
  204.     LVAL object, data;
  205. {
  206.   int i, n, oldn, vars, width;
  207.   StGWWinInfo /* char */ *gwinfo = IViewWindowWinInfo(w); /* changed JKL */
  208.   LVAL arg;
  209.   
  210.   vars = IViewNumVariables(w);
  211.   oldn = IViewNumLines(w);
  212.   n = check_locations(data, vars);
  213.   
  214.   IViewAddLines(w, n);
  215.   n = IViewNumLines(w);
  216.   set_locations(w, object, 'L', data, vars, oldn, n);
  217.  
  218.   if (xlgetkeyarg(sk_type, &arg) && arg != s_solid)
  219.     for (i = oldn; i < n; i++) IViewSetLineType(w, i, 1);
  220.   if (xlgetkeyarg(sk_color, &arg)) {
  221.     StGWSetUseColor(gwinfo, TRUE);
  222.     for (i = oldn; i < n; i++)
  223.       IViewSetLineColor(w, i, decode_lisp_color(arg));
  224.   }
  225.   if (xlgetkeyarg(sk_width, &arg) && fixp(arg)) {
  226.     width = getfixnum(arg);
  227.     for (i = oldn; i < n; i++)
  228.       IViewSetLineWidth(w, i, width);
  229.   }
  230. }
  231.  
  232. LVAL iview_add_lines()
  233. {
  234.   IVIEW_WINDOW w;
  235.   LVAL object, data;
  236.   int n, oldn;
  237.   
  238.   object = xlgaobject();
  239.   w = get_iview_address(object);
  240.   data = xlgetarg();
  241.  
  242.   oldn = IViewNumLines(w);
  243.   internal_iview_add_lines(w, object, data);
  244.   n = IViewNumLines(w);
  245.   check_add_to_screen(object, 'L', oldn, n, FALSE);
  246.   return(NIL);
  247. }
  248.   
  249. LVAL iview_clear_lines() { return(clear_data('L')); }
  250.  
  251. #ifdef USESTRINGS
  252. /**************************************************************************/
  253. /**                                                                      **/
  254. /**                     IView String Data Functions                      **/
  255. /**                                                                      **/
  256. /**************************************************************************/
  257.  
  258. void internal_iview_add_strings(w, object, data)
  259.     IVIEW_WINDOW w;
  260.     LVAL object, data;
  261. {
  262.   LVAL strings;
  263.   int i, n, oldn, vars;
  264.   char *str;
  265.   
  266.   strings = xlgetarg();
  267.   
  268.   vars = IViewNumVariables(w);
  269.   oldn = IViewNumStrings(w);
  270.   n = check_locations(data, vars);
  271.   check_strings(n, strings);
  272.   
  273.   IViewAddStrings(w, n);
  274.   n = IViewNumStrings(w);
  275.   set_locations(w, object, 'S', data, vars, oldn, n);
  276.   
  277.   for (i = oldn; i < n; i++) {
  278.     str = (char *) getstring(getnextelement(&strings, i - oldn));
  279.     IViewSetStringString(w, i, str);
  280.   }
  281. }
  282.  
  283. LVAL iview_add_strings()
  284. {
  285.   IVIEW_WINDOW w;
  286.   LVAL object, data;
  287.   int n, oldn;
  288.   
  289.   object = xlgaobject();
  290.   w = get_iview_address(object);
  291.   data = xlgetarg();
  292.  
  293.   oldn = IViewNumStrings(w);
  294.   internal_iview_add_strings(w, object, data);
  295.   n = IViewNumStrings(w);
  296.   check_add_to_screen(object, 'S', oldn, n, FALSE);
  297.   return(NIL);
  298. }
  299.  
  300. LVAL iview_clear_strings() { return(clear_data('S')); }
  301. #endif /* USESTRINGS */
  302.  
  303. /**************************************************************************/
  304. /**                                                                      **/
  305. /**                     Standard Callback Functions                      **/
  306. /**                                                                      **/
  307. /**************************************************************************/
  308.  
  309. LVAL iview_std_resize()
  310. {
  311.   IVIEW_WINDOW w;
  312.  
  313.   w = get_iview_address(xlgaobject());
  314.   IViewStdResize(w);
  315.   return(NIL);
  316. }
  317.  
  318. LVAL iview_std_redraw()
  319. {
  320.   IVIEW_WINDOW w;
  321.  
  322.   w = get_iview_address(xlgaobject());
  323.   IViewStdRedraw(w);
  324.   return(NIL);
  325. }
  326.  
  327. LVAL iview_std_redraw_background()
  328. {
  329.   IVIEW_WINDOW w;
  330.  
  331.   w = get_iview_address(xlgaobject());
  332.   IViewStdRedrawBackground(w);
  333.   return(NIL);
  334. }
  335.  
  336. LVAL iview_std_redraw_content()
  337. {
  338.   IVIEW_WINDOW w;
  339.  
  340.   w = get_iview_address(xlgaobject());
  341.   IViewStdRedrawContent(w);
  342.   return(NIL);
  343. }
  344.  
  345. void IViewRedrawBackground(w)
  346.     IVIEW_WINDOW w;
  347. {
  348.   send_message((LVAL) IViewWindowGetObject(w), sk_redraw_background);
  349. }
  350.  
  351. void IViewRedrawContent(w)
  352.     IVIEW_WINDOW w;
  353. {
  354.   send_message((LVAL) IViewWindowGetObject(w), sk_redraw_content);
  355. }
  356.  
  357. void IViewRedrawOverlays(w)
  358.     IVIEW_WINDOW w;
  359. {
  360.   send_message((LVAL) IViewWindowGetObject(w), sk_redraw_overlays);
  361. }
  362.  
  363. void IViewResizeOverlays(w)
  364.     IVIEW_WINDOW w;
  365. {
  366.   send_message((LVAL) IViewWindowGetObject(w), sk_resize_overlays);
  367. }
  368.  
  369. /**************************************************************************/
  370. /**                                                                      **/
  371. /**                        Miscellaneous Functions                       **/
  372. /**                                                                      **/
  373. /**************************************************************************/
  374.  
  375. void check_add_to_screen(object, which, old_n, n, redraw)
  376.     LVAL object;
  377.     int old_n, n, redraw;
  378. {
  379.   IVIEW_WINDOW w;
  380.   StGWWinInfo /* char */ *gwinfo; /* changed JKL */
  381.   int x, y;
  382.   LVAL adjust;
  383.   
  384.   w = get_iview_address(object);
  385.   gwinfo = StGWObWinInfo(object);
  386.   if (! xlgetkeyarg(sk_draw, &adjust)) adjust = s_true;
  387.   
  388.   if (adjust != NIL) {
  389.     if (redraw || old_n == 0) send_message(object, sk_redraw_content);
  390.     else {
  391.       StGrGetContentVariables(gwinfo, &x, &y);
  392.       switch(which) {
  393.       case 'P': IViewDrawDataPoints(w, x, y, old_n, n);   break;
  394.       case 'L': IViewDrawDataLines(w, x, y, old_n, n);    break;
  395. #ifdef USESTRINGS
  396.       case 'S': IViewDrawDataStrings(w, x, y, old_n, n);  break;
  397. #endif /* USESTRINGS */
  398.       }
  399.     }
  400.   }
  401. }
  402.  
  403. void check_redraw(object, deflt, content_only)
  404.     LVAL object;
  405.     int deflt, content_only;
  406. {
  407.   LVAL arg, msg;
  408.   int redraw;
  409.   
  410.   if (xlgetkeyarg(sk_draw, &arg)) redraw = (arg != NIL);
  411.   else redraw = deflt;
  412.   
  413.   msg = (content_only) ? sk_redraw_content : sk_redraw;
  414.   if (redraw) send_message(object, msg);
  415. }
  416.  
  417. int draw_key_arg(deflt)
  418.     int deflt;
  419. {
  420.   int value = deflt, n, i;
  421.   
  422.   for (n = xlargc - 1, i = 0; i < n; i++) {
  423.     if (sk_draw == xlargv[i]) {
  424.       value = (xlargv[i+1] != NIL) ? TRUE : FALSE;
  425.     }
  426.   }
  427.   return(value);
  428. }
  429.